home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #6 / Amiga Plus CD - 2004 - No. 06.iso / AmiSoft / Comm / mail / YahooGpScan1_5.lha / YahooGroupsScanner.rexx < prev   
OS/2 REXX Batch file  |  2004-05-29  |  11KB  |  287 lines

  1. /* Strip YahooGroups script for YAM
  2.  *     $VER: Strip YahooGroups script 1.5 (29-May-2004)
  3.  *   Author: ©2000-01 Steve Bowman (stevebow@hotkey.net.au)
  4.  * Function: This script serves to strip those annoying YahooGroups adverts that appear in every e-mail sent out.
  5.  */
  6.  
  7. options results
  8.  
  9. /* Add rexxsupport.library if it isn't already open. */
  10. if ~show('libraries','rexxsupport.library') then do
  11.    /* If the library isn't open, try to open it */
  12.    if ~addlib('rexxsupport.library',0,-30,0) then do
  13.       say 'rexxsupport.library not found.'
  14.       exit 10
  15.    end
  16. end
  17.  
  18. BeginSeparater   = '------------------------ Yahoo! Groups Sponsor --------------------~-->'
  19. EndSeparater     = '--------------------------------------------------------------------~->'
  20. TotalNewMessages = 0
  21. AdvertsRemoved   = 0
  22.  
  23. address YAM
  24.  
  25. /**** Locate the Incoming directory ****/
  26. call FindIncoming
  27. parse var result IncomingPath IncomingFolder
  28.  
  29. call StoreCurrentYamState                                  /**** Store current YAM state ****/
  30.  
  31. address COMMAND 'List '||IncomingPath||' LFORMAT %p%n >T:TempFileList'    /**** List the Incoming Folder's messages to temporary file using real filenames ****/
  32.  
  33. call open('FileList','T:TempFileList')                    /**** Build a New Message file list ****/
  34. call open('NewMessageList','T:TempNewMessageList','write')
  35.  
  36. do until eof('FileList')
  37.    MessageName = readln('FileList')
  38.    if left(subword(statef(MessageName),8,1),1) ~= 'N' then iterate
  39.    call writeln('NewMessageList',MessageName)
  40.    TotalNewMessages = TotalNewMessages + 1
  41. end
  42.  
  43. call close('NewMessageList')
  44. call close('FileList')
  45.  
  46. if TotalNewMessages < 1 then call GoodBye
  47.  
  48. call StatusRequesterBuild                                  /**** Open the GUI ****/
  49.  
  50. call open('NewMessageList','T:TempNewMessageList')         /**** Start the scan, file by file ****/
  51.  
  52. do MessagesSofar = 1 to TotalNewMessages
  53.  
  54.    call ToPipe('tick 0')                                   /**** Check if User wants to abort by either hitting Abort or window close gadgets ****/
  55.    res = readln('StatusGUI')
  56.    parse var res res1 res2 .
  57.    if res1 = 'close' | res1 = 'gadget' & res2 = QUITID then call GoodBye
  58.  
  59.    AdvertStripped = 0
  60.    CurrentFileName = readln('NewMessageList')
  61.    call open('CurrentMessage',CurrentFileName)
  62.    call open('WriteFile','T:TempFileOut','write')
  63.  
  64.    /**** Read and Write message lines until To: Header is reached ****/
  65.    do until eof('CurrentMessage') | upper(left(CurrentLine,3)) = 'TO:'    /* Do uppercase-only checking due to incidences where To: header can be to: or TO: or even tO: :^) */
  66.       CurrentLine = readln('CurrentMessage')
  67.       call writeln('WriteFile',CurrentLine)
  68.    end
  69.  
  70.    /**** Iterate if To: does not contain "yahoogroups" ****/
  71.    if pos('YAHOOGROUPS',upper(CurrentLine)) = 0 then do        /* Do uppercase-only checking due to incidences where To: field contains a mixed case address */
  72.       call close('WriteFile')
  73.       call close('CurrentMessage')
  74.       call StatusRequesterUpdate(MessagesSofar,TotalNewMessages,AdvertsRemoved)
  75.       iterate
  76.    end
  77.  
  78.    /**** Read and Write message lines until BeginSeparater is reached ****/
  79.    CurrentLine = readln('CurrentMessage')
  80.    do until eof('CurrentMessage') | CurrentLine = BeginSeparater
  81.       call writeln('WriteFile',CurrentLine)
  82.       CurrentLine = readln('CurrentMessage')
  83.    end
  84.  
  85.    /**** Read-Only message lines until EndSeparater is reached ****/
  86.    do until eof('CurrentMessage') | CurrentLine = EndSeparater
  87.       CurrentLine = readln('CurrentMessage')
  88.       if CurrentLine = EndSeparater then do
  89.          AdvertStripped = 1
  90.          CurrentMessageStatus=subword(statef(CurrentFileName),8,1)       /* Storing message status, stored in the file's comment, for later restore */
  91.       end
  92.    end
  93.    call readln('CurrentMessage')
  94.  
  95.    /**** Now append the rest of the message, line by line ****/
  96.    CurrentLine = readln('CurrentMessage')
  97.    do while ~eof('CurrentMessage')
  98.       call writeln('WriteFile',CurrentLine)
  99.       CurrentLine = readln('CurrentMessage')
  100.    end
  101.  
  102.    call close('WriteFile')
  103.    call close('CurrentMessage')
  104.    if AdvertStripped = 1 then do
  105.       address COMMAND 'Copy T:TempFileOut '||CurrentFileName||' QUIET'
  106.       address COMMAND 'Filenote '||CurrentFileName||' '||CurrentMessageStatus||' QUIET'
  107.       AdvertsRemoved = AdvertsRemoved + 1
  108.    end
  109.    call StatusRequesterUpdate(MessagesSofar,TotalNewMessages,AdvertsRemoved)
  110.  
  111. end
  112.  
  113. if AdvertsRemoved > 0 then do
  114.    call ToPipe('id 0 selected 8 gadgettext="Updating Incoming Folder..."')
  115.    setfolder IncomingFolder
  116.    mailupdate
  117.    call RetrievePreviousYamState
  118. end
  119.  
  120. call delete('T:TempFileOut')
  121.  
  122. call GoodBye
  123.  
  124. exit
  125. /* ======== End Main Routine =============================================== */
  126.  
  127. FindIncoming:
  128.  
  129. userinfo stem userinfo.
  130. SettingsDirectory = userinfo.maildir
  131. if right(SettingsDirectory,1) ~= '/' & right(SettingsDirectory,1) ~= ':' then SettingsDirectory = SettingsDirectory||'/'    /**** Add trailing '/' in path name if it is not present, but only if trailing char is not a ':' ****/
  132.  
  133. IncomingCount = -1
  134.  
  135. if open('FolderList',SettingsDirectory||'.folders') then do
  136.    call readln('FolderList')                               /**** skip first line in .folders file ****/
  137.  
  138.    do while ~eof('FolderList')
  139.       IncomingCount = IncomingCount + 1
  140.       call readln('FolderList')
  141.       FolderDirectory = readln('FolderList')
  142.  
  143.       if FolderDirectory = "" then break
  144.  
  145.       if left(FolderDirectory,1) = "@" then iterate
  146.  
  147.       if index(FolderDirectory,":") = 0 then FolderDirectory = SettingsDirectory||FolderDirectory    /**** If the full pathname (ie. root device) is not present in .folders file, add it.  I hope this satisfies all possibilities! ****/
  148.  
  149.       if open('FolderConfigFile',FolderDirectory||'/.fconfig') then do
  150.  
  151.          do for 5
  152.             ConfigLine = readln('FolderConfigFile')        /**** skip 5 lines ****/
  153.          end
  154.  
  155.          if ConfigLine = 'Type        = 1' then do         /**** This checks if the folder is really the incoming one, regardless of name or location in folder list ****/
  156.             call close('FolderConfigFile')
  157.             call close('FolderList')
  158.             return FolderDirectory IncomingCount           /**** return here ****/
  159.          end
  160.  
  161.       end
  162.  
  163.       else do                                              /**** Cannot find .fconfig file in folder directory ****/
  164.          say 'Cannot find .fconfig file in directory: '||FolderDirectory
  165.       end
  166.  
  167.       call close('FolderConfigFile')
  168.       call readln('FolderList')
  169.  
  170.    end
  171.  
  172.    say 'Cannot find the Incoming folder!'                  /**** Cannot find the Incoming folder ****/
  173.    call close('FolderList')
  174.    exit
  175.  
  176. end
  177.  
  178. else do                                                    /**** Cannot find the .folders config file ****/
  179.    say 'Cannot find the .folders config file!'
  180.    exit
  181. end
  182.  
  183. return                                                     /**** Should never get here... ****/
  184. /* ========================================================================= */
  185.  
  186. StoreCurrentYamState:
  187.  
  188. folderinfo stem CurrentFolder.
  189. mailinfo stem CurrentMessage.
  190. getselected stem SelectedMessages.
  191.  
  192. return
  193. /* ========================================================================= */
  194.  
  195. RetrievePreviousYamState:
  196.  
  197. setfolder CurrentFolder.number
  198. setmail CurrentMessage.index
  199. do Loop = 0 to SelectedMessages.num.count - 1
  200.    listselect SelectedMessages.num.Loop
  201. end
  202.  
  203. return
  204. /* ========================================================================= */
  205.  
  206. StatusRequesterBuild:
  207.  
  208. call open('StatusGUI',"awnpipe:ScannerGUI/xc")
  209.  
  210. call ToPipe('title "Advert Scanner" dragbar closegadget vertical centerscreen modify')
  211.    call ToPipe('layout vertical bevel=1 spaceouter')
  212.       call ToPipe('layout bevel=0')
  213.          call ToPipe('space minwidth=10')
  214.          call ToPipe('layout vertical bevel=0')
  215.             call ToPipe('space minheight=10')
  216.             FuelGaugeID = ToPipe('fuelgauge ticks 21 percent defnumber 0')
  217.             call ToPipe('space minheight=10')
  218.             call ToPipe('label ua gadgettext "New messages scanned: "')
  219.             NewMessagesID = ToPipe('button gadgettext "0" minwidth=40 readonly childlabel')
  220.             call ToPipe('label ua gadgettext "Adverts removed: "')
  221.             AdvertsRemovedID = ToPipe('button gadgettext "0" minwidth=40 readonly childlabel')
  222.             call ToPipe('space minheight=10')
  223.          call ToPipe('layoutend')
  224.          call ToPipe('space minwidth=10')
  225.       call ToPipe('layoutend')
  226.       call ToPipe('layout bevel=7' vertical)
  227.          call ToPipe('space minheight=5')
  228.          call ToPipe('layout bevel=0')
  229.          call ToPipe('space')
  230.          QuitID = ToPipe('button gadgettext "_Abort" weightedwidth 0 close')
  231.          call ToPipe('space')
  232.       call ToPipe('layoutend')
  233.       call ToPipe('space minheight=5')
  234.    call ToPipe('layoutend')
  235. GUIopen = ToPipe('open')
  236.  
  237. return
  238. /* ========================================================================= */
  239.  
  240. StatusRequesterUpdate:
  241.  
  242. parse arg GuiMessagesSofar,GuiTotalNewMessages,GuiAdvertsRemoved
  243.  
  244. Percentage = trunc(GuiMessagesSofar / GuiTotalNewMessages * 100 + .5)
  245.  
  246. call ToPipe('id '||FuelGaugeID||' defnumber="'||Percentage||'"')
  247. call ToPipe('id '||NewMessagesID||' gadgettext="'||GuiMessagesSofar||'"')
  248. call ToPipe('id '||AdvertsRemovedID||' gadgettext="'||GuiAdvertsRemoved||'"')
  249.  
  250. if GuiMessagesSofar = GuiTotalNewMessages then do
  251.    call ToPipe('id '||QuitID||' gadgettext="_Ok"')
  252. end
  253.  
  254. return
  255. /* ========================================================================= */
  256.  
  257. ToPipe:                                                    /**** this routine does error checking on lines written to pipe ****/
  258.  
  259. parse arg out                                              /**** get line to output ****/
  260.  
  261. call writeln('StatusGUI',out)                              /**** write to the pipe ****/
  262.  
  263. ResultText = readln('StatusGUI')                           /**** get response and parse it ****/
  264. parse var ResultText ResultText1 ResultText2 .
  265.  
  266. if ResultText1 = 'ok' then return(ResultText2)             /**** if all is ok return the second part of the response (usualy the GID) ****/
  267.  
  268. say 'error from: 'out                                      /**** something went wrong, we notify the user then exit, show problem line and response (reponse may be just a blank line) ****/
  269.  
  270. call GoodBye
  271.  
  272. /* ========================================================================= */
  273.  
  274. GoodBye:
  275.  
  276. if GUIopen = 'window' then do                              /**** If GUI is open then close it ****/
  277.    call ToPipe('tick 50')                                  /**** Delay in 1/100 sec for GUI to close ****/
  278.    call close('StatusGUI')                                 /**** Close GUI ****/
  279. end
  280.  
  281. call close('NewMessageList')
  282.  
  283. call delete('T:TempNewMessageList')
  284. call delete('T:TempFileList')
  285.  
  286. exit
  287.